/****************************************************
	文件：EntityBase.cs
	作者：HuskyT
	邮箱：1005240602@qq.com
	日期：2020/5/31 18:18:40
	功能：实体  基类
*****************************************************/

using System.Collections.Generic;
using System.Linq;

namespace AIModule.Utility.Example
{
    public class EntityBase
    {
        /// <summary>
        /// 命令队列
        /// </summary>
        protected Queue<CommandBase> mCommandQue;
        /// <summary>
        /// AI
        /// </summary>
        protected AIBase mAI;
        /// <summary>
        /// 实体数据
        /// </summary>
        public ModelBase Model { protected set; get; }
        /// <summary>
        /// 黑板数据项（用于 AI 模块传递数据）
        /// </summary>
        public BlackboardItem BB { protected set; get; }

        /// <summary>
        /// 添加命令
        /// </summary>
        public void AddCommand(CommandBase command)
        {
            CommandMemento.Instance.AddCommand(command, BB);
            mCommandQue.Enqueue(command);
        }
        /// <summary>
        /// 移除命令
        /// </summary>
        public void RemoveCommand(CommandBase command)
        {
            CommandMemento.Instance.RemoveCommand(command, BB);
            List<CommandBase> commandList = mCommandQue.ToList();
            commandList.Remove(command);
            mCommandQue.Clear();
            foreach (var item in commandList)
            {
                mCommandQue.Enqueue(item);
            }
        }
        /// <summary>
        /// 执行命令
        /// </summary>
        public void ExecuteCommand()
        {
            mCommandQue.Dequeue().Execute(BB);
        }
        /// <summary>
        /// 执行当前命令队列中所有的命令
        /// </summary>
        public void ExecuteAllCommand()
        {
            while (mCommandQue.Count > 0)
            {
                ExecuteCommand();
            }
        }
        /// <summary>
        /// 设置对手
        /// </summary>
        public void SetOpponent(EntityBase entity)
        {
            BB.OpponentModel = entity.Model;
        }

        /// <summary>
        /// 打印实体状态
        /// </summary>
        public override string ToString()
        {
            int minAtk = Model.Atk.Value - Model.AtkRangeRadius.Value;
            int maxAtk = Model.Atk.Value + Model.AtkRangeRadius.Value;
            return string.Format("{0} 当前状态：\nHp : {1} ({2})\nAtk : {3} ~ {4}\nDef : {5}\nCurativePotion : {6}", Model.Name, Model.Hp.Value, Model.MaxHp.Value, minAtk, maxAtk, Model.Def.Value, Model.CurativePotionNum.Value);
        }
        public string Logging()
        {
            return string.Format("{0} 当前状态：\nHp : {1} ({2})\nCurativePotion : {3}", Model.Name, Model.Hp.Value, Model.MaxHp.Value, Model.CurativePotionNum.Value);
        }
    }
}